const { baseConfig } = require("./config.js");
class Axios {
  post(url, data) {
    return this.request("POST", url, data)
  }
  get(url, data) {
    return this.request("GET", url, data)
  }
  put(url, data) {
    return this.request("PUT", url, data)
  }
  update(url, data) {
    return this.request("UPDATE", url, data)
  }
  detete(url, data) {
    return this.request("DELETE", url, data)
  }
  request(method, url, data) {
    console.log(data)
    return new Promise((resolve, reject) => {
      wx.request({
        url: baseConfig.apiBaseUrl + url,
        method: method,
        data:data,
        header: {
          "content-type": 'application/x-www-form-urlencoded'//默认值
        },
        success(res) {
          console.log(res.data);//打印返回的数据
          resolve(res.data)
        },
        fail(err) {
          console.log(err)
          reject(err)
        }
      })
    })
  }
}
module.exports = new Axios();//将其暴露出去